/**
 *
 * Description: 
 *
 * @author lirong
 * @version 1.0
 * <pre>
 * Modification History: 
 * Date         Author      Version     Description 
 * ------------------------------------------------------------------ 
 * 2012-3-15    lirong       1.0        1.0 Version 
 * </pre>
 */

package com.creditease.rss.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.webkit.WebView;
import android.widget.TextView;

/**
 * 
 * Description:
 * 
 * @author lirong
 * @version 1.0
 * 
 *          <pre>
 * Modification History: 
 * Date         Author      Version     Description 
 * ------------------------------------------------------------------ 
 * 2012-3-15    lirong       1.0        1.0 Version
 * </pre>
 */

public class RssReader2 extends Activity {
	private WebView webView;
	private float startX;
	private float endX;
	private String link;
	private TextView titleText;
	private String title;
	private String htmlContext;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

		setContentView(R.layout.rss_reader2);
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);

		webView = (WebView) findViewById(R.id.webView2);

		Intent intent = getIntent();
		String url = intent.getExtras().getString("url");
		link = intent.getExtras().getString("link");
		title = intent.getExtras().getString("title");
		Long id = intent.getExtras().getLong("id");
		String sectionId = intent.getExtras().getString("sectionId");
/*
		List<RssItemModel> items = CacheMgr.getList(sectionId);
		final RssItemModel bean = items.get(id.intValue());

		// 标题
		titleText = (TextView) findViewById(R.id.titleText);
		titleText.setText(title);

		StringBuilder buf = new StringBuilder();
		buf.append(bean.content);

		System.out.println("description=" + bean.content);
		System.out.println("link=" + link);
		System.out.println("link2=" + bean.articleLink);
		webView.getSettings().setDefaultTextEncodingName("UTF-8");
		// webView.loadData(buf.toString(), "text/html", "UTF-8");
		htmlContext = bean.content;
		webView.getSettings().setJavaScriptEnabled(true);
		webView.addJavascriptInterface(this, "rssSupport");
		webView.getSettings().setBuiltInZoomControls(true);
		webView.loadUrl("file:///android_asset/basic.html");*/

	/*	WebViewClient wvc = new WebViewClient() {
			@Override
			public void onPageFinished(WebView view, String url) {
				System.out.println("showHtmlshowHtmlshowHtml");
				webView.loadUrl("javascript:showHtml('" + htmlContext + "')");
				System.out.println("showHtmlshowHtml=======");
				super.onPageFinished(view, url);
			}
		};*/
		// webView.setWebViewClient(wvc);

	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// 第一次按下事件
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			startX = event.getX();
		} else if (event.getAction() == MotionEvent.ACTION_UP) {
			endX = event.getX();
			// 从左往右
			if (startX < endX) {

			} else if (startX > endX) {

			}
		}

		return super.onTouchEvent(event);
	}

	public void openDetailPage(View view) {

		Intent intent = new Intent();
		intent.setClass(getApplicationContext(), RssReaderDetail.class);
		intent.putExtra("url", link);
		intent.putExtra("title", title);

		startActivity(intent);
	}

	/**
	 * 获取数据 description
	 */
	public void getHTML() {
		System.out.println("showHtmlshowHtmlshowHtml");
		webView.loadUrl("javascript:showHtml('" + htmlContext + "')");
		System.out.println("showHtmlshowHtml=======");
	}
}
